﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using SmartMD.DataModel.Entity;
using System.ComponentModel;
using Techstar.Dialog;
using Duoease.ContainerModel;

namespace SmartMD.Manager.Specimens
{
    /// <summary>
    /// Interaction logic for SiteSelectWindow.xaml
    /// </summary>
    public partial class SiteSelectDialog : Window
    {
        private SpecStoreEditPad _owner;
        public ContainerModelView _CM = null;
        public string ContainerID = "";

        public List<string> selectedSitecodeList = new List<string>();
        public List<string> sitecodeList = new List<string>();
 
        public ObservableCollection<SiteSelectEntity> selectEntityList;

        public SiteSelectDialog(SpecStoreEditPad owner, int itemNum, string specId)
        {
            InitializeComponent();
            _owner = owner;
            selectEntityList = new ObservableCollection<SiteSelectEntity>();
            SiteSelectEntity item = null;
            for(int i=0; i<itemNum;i++)
            {
                item = new SiteSelectEntity();
                item.Id = System.Guid.NewGuid().ToString();
                item.SpecId = specId;
                item.SpecName = "标本" + (i + 1).ToString();
                selectEntityList.Add(item);
            }
            
            ICollectionView view = CollectionViewSource.GetDefaultView(selectEntityList);

            this.indiceListview.ItemsSource = view;
            
        }
        private ObservableCollection<SiteSelectEntity> _dataSource;
        public ObservableCollection<SiteSelectEntity> DataSource
        {
            get
            {
                return _dataSource;
            }
            set
            {
                _dataSource = value;
                
                this.DataContext = _dataSource;
            }
        }

        private void ContainerSelect_Click(object sender, RoutedEventArgs e)
        {
            
            int index = this.indiceListview.SelectedIndex;
            SiteSelectWindow selectWnd = new SiteSelectWindow(sender, this);
           
            selectWnd.ShowDialog();     
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            //验证用户操作是否合法
            //TO DO...
            for (int j = 0; j < this.selectEntityList.Count; j++)
            {
                if (this.selectEntityList[j].SiteCode == null)
                {
                    TaskDialogEx.Warning("提示", "请将所有标本的位置关联！");
                    return;
                }
            }
            if (_owner != null)
            {
                _owner.DataSource.SiteEntityList = this.selectEntityList;
            }
            this._owner.txtContainer.Text = "已存入";
            this._owner.Positon = this.selectEntityList[0].SiteCode;
            this._owner._CM = _CM;
            this._owner.ContainerID = ContainerID;
            this._owner.BtnSearchSite.IsEnabled = false;
            this._owner.BtnStoreSpecFast.IsEnabled = false;
            this.Close();
        }
    }
}
